import React from 'react'
import { increment, decrement } from '../../store/slice/countSlice'
import { useSelector, useDispatch } from "react-redux"

export default function Count() {
  const dispatch = useDispatch()

  const count = useSelector(state => state.count.count)

  const incrementcount = () => {
    dispatch(increment(10))
  }

  const decrementcount = () => {
    dispatch(decrement(2))
  }

  const Odddecrementcount = () => {
    if (count % 2 !== 0) {
      dispatch(increment(10))
    }
  }

  const waitdecrementcount = () => {

  }

  return (
    <div>
      <p>值为:{count}</p>
      <h1>接收到个电影</h1>
      <button onClick={incrementcount}>累加</button>
      <button onClick={decrementcount}>累减</button>
      <button onClick={Odddecrementcount}>奇数加</button>
      <button onClick={waitdecrementcount}>等2秒加</button>
    </div>
  )
}
